package com.glut.campusrepair.controller;

import com.glut.campusrepair.entity.MaterialPurchases;
import com.glut.campusrepair.service.IMaterialPurchasesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 材料采购表 前端控制器
 *
 * @author sanminzhi
 * @since 2024-07-19 11:26
 */
@RestController
public class MaterialPurchasesController {

    IMaterialPurchasesService iMaterialPurchasesService;

    @Autowired
    public MaterialPurchasesController(IMaterialPurchasesService iMaterialPurchasesService){
        this.iMaterialPurchasesService = iMaterialPurchasesService;
    }

    @PostMapping("/mp/buy")
    public MaterialPurchases saveMaterialPurchases(@RequestBody MaterialPurchases materialPurchases){
        return iMaterialPurchasesService.saveMaterialPurchases(materialPurchases);
    }

    @GetMapping("/mp/list")
    public List<MaterialPurchases> getAllPurchases() {
        return iMaterialPurchasesService.getPurchases();
    }

    @PostMapping("/mp/agree")
    public boolean agreePurchase(@RequestBody MaterialPurchases materialPurchases) {
        return iMaterialPurchasesService.agreePurchase(materialPurchases);
    }

    @PostMapping("/mp/reject")
    public boolean rejectPurchase(@RequestBody MaterialPurchases materialPurchases) {
        return iMaterialPurchasesService.rejectPurchase(materialPurchases);
    }

    @GetMapping("/mp/recent")
    public List<MaterialPurchases> getRecentAgreedPurchases() {
        return iMaterialPurchasesService.getRecentAgreedPurchases();
    }
}
